#include "Common/Assertion.h"
#include <cstdio>
#include <cstring>

Assertion::Assertion(
	const char* file,
	int line,
	const char* reason)
{
	const int max_msg_size = 512;
	char buf[max_msg_size];

	_snprintf(buf, max_msg_size, "%s(%d):\n%s", file, line, reason);
	buf[max_msg_size - 1] = '\0';

	const size_t msg_size = strlen(buf) + 1;
	char* message = new char[msg_size];
	std::strncpy(message, buf, msg_size);
	m_message = message;
}

Assertion::Assertion(
	const char* file,
	int line,
	const char* reason,
	const char* more_info)
{
	// XXX: clean copy & paste from above
	const int max_msg_size = 512;
	char buf[max_msg_size];

	_snprintf(buf, max_msg_size, "%s(%d):\n%s. %s", file, line, reason, more_info);
	buf[max_msg_size - 1] = '\0';

	const size_t msg_size = strlen(buf) + 1;
	char* message = new char[msg_size];
	std::strncpy(message, buf, msg_size);
	m_message = message;	
}

const char* Assertion::message() const
{
	return m_message;
}
